<?php

namespace app\modules\admin\controllers;

use app\common\controllers\AccessController;
use app\modules\admin\forms\category\MerchantCategoryForm;
use app\modules\admin\services\MerchantCategoryService;
use yii\base\UserException;

class MerchantCategoryController extends AccessController {

    //搜索
    public function actionSearch(){
        return [
            'list'=>MerchantCategoryService::getList(0),
        ];
    }

    //添加
    public function actionAdd(){
        $form = new MerchantCategoryForm();
        $form->setScenario("create");

        if($form->load(\Yii::$app->getRequest()->post(),'') && MerchantCategoryService::create($form)){
           return "";
        }else{
            throw new UserException(MerchantCategoryService::getError());
        }
    }

    //获取信息
    public function actionGetInfoById($id){
        return MerchantCategoryService::getInfoById($id);
    }

    //编辑
    public function actionEdit(){
        $form = new MerchantCategoryForm();
        $form->setScenario("update");

        if($form->load(\Yii::$app->getRequest()->post(),'') && MerchantCategoryService::update($form)){
            return "";
        }else{
            throw new UserException(MerchantCategoryService::getError());
        }
    }

    //删除
    public function actionDelete($id){
        MerchantCategoryService::delete($id);
        return "";
    }
}